package annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-28 19:29
 **/
public class RunDemo {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //获取所有的类,
        List<String> classList = new ArrayList<>();
        classList.add("annotation.annotationTest");
        for (String s : classList) {

            Class<?> clazz = Class.forName(s);
            Object instance = clazz.getConstructor().newInstance();
            //找到对应的类,通过对应的clazz看看上面有没有注解@Test1
            Method[] methods = clazz.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                Method method = methods[i];
                method.setAccessible(true);
                if (method.isAnnotationPresent(Test1.class)) {

                    //说明有注解
                    //如果有注解,就执行
                    method.invoke(instance);
                }
                //如果没有就不要执行
            }

        }

    }
}
